package com.ruoyi.ratedemo.rate;

import com.ruoyi.ratedemo.domain.Friend;
import com.ruoyi.ratedemo.domain.Rate;
import com.ruoyi.ratedemo.service.FriendService;
import com.ruoyi.ratedemo.vo.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/friends")
public class FriendController {
    @Autowired
    private FriendService friendService;

    @GetMapping("/get/{userId}")
    public Result getFriendsByUserID(@PathVariable int userId){
        return Result.success(friendService.getFriendsByUserId(userId));
    }

    @PostMapping("/add")
    public Result addFriend(@RequestBody Friend friend) {
        int userId = friend.getUserId();
        int friendId = friend.getFriendId();
        friendService.addFriend(userId,friendId);
        return Result.success();
    }
    @DeleteMapping("/delete")
    public Result removeFriend(@RequestBody Friend friend) {
        int userId = friend.getUserId();
        int friendId = friend.getFriendId();
        friendService.deleteFriend(userId, friendId);
        return Result.success();
    }
}
